/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uit.qlks.controller.user;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.sql.rowset.WebRowSet;
import uit.ejb.bo.user.UserBORemote;
import uit.ejb.bo.user.UserBORemoteHome;
import uit.ejb.dto.UserDTO;

/**
 *
 * @author SVN - Team
 */
public class UserController {

    private static Context ctx;
    private static UserBORemoteHome phome;
    private static UserBORemote us;

    public UserController() {
    }

    public static void Register() {
        try {
            ctx = new InitialContext();
            Object obj = ctx.lookup("ejb/UserBO");
            phome = (UserBORemoteHome) PortableRemoteObject.narrow(obj, UserBORemoteHome.class);
            us = phome.create();
        } catch (Exception e) {
        }
    }

    public static WebRowSet user_GetByAll() {
        try {
            Register();
            return us.user_GetByAll();
        } catch (Exception ex) {
            return null;
        }
    }

    public static boolean user_Insert(UserDTO user) {
        try {
            Register();
            return us.user_Insert(user);
        } catch (Exception e) {
            return false;
        }
    }

    public static boolean user_Update(UserDTO user) {
        try {
            Register();
            return us.user_Update(user);
        } catch (Exception e) {
            return false;
        }
    }

    public static int user_Delete(String id) {
        try {
            Register();
            return us.user_Delete(id);
        } catch (Exception e) {
            return 0;
        }
    }

    public static WebRowSet user_GetById(UserDTO user) {
        try {
            Register();
            return us.user_GetById(user);
        } catch (Exception e) {
            return null;
        }
    }

    public static WebRowSet user_GetByTop(String top, String where, String order) {
        try {
            Register();
            return us.user_GetByTop(top, where, order);
        } catch (Exception e) {
            return null;
        }
    }

    public static int user_CheckLogin(String user,String pass){
        try{
            Register();
            return us.user_CheckLogin(user,pass);
        }catch(Exception e){
            return -1;
        }
    }
}
